package top.majuan.study.study.entity;

import java.io.Serializable;

/**
 * 统一应答结果对象
 */
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private Boolean success;
    private Integer code;
    private String message;
    private T data;


    public void setInfo(Boolean success, Integer code, String message) {
        this.code = code;
        this.message = message;
        this.success = success;
    }

    public static <T> Result<T> success(String message) {
        Result<T> result = new Result<>();
        result.setInfo(true, 200,message);
        return result;
    }

    public static <T> Result<T> success(String message, T data) {
        Result<T> result = new Result<>();
        result.setInfo(true, 200,message);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(String message, T data) {
        Result<T> result = new Result<>();
        result.setInfo(false, 500,message);
        result.setData(data);
        return result;
    }

    @Override
    public String toString() {
        return "Result{" +
                "success=" + success +
                ", code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
